package cn.edu.scau.cmi.chenxiaoqin.client;

import cn.edu.scau.cmi.chenxiaoqin.abstractFactory.Beef;
import cn.edu.scau.cmi.chenxiaoqin.abstractFactory.Brand;
import cn.edu.scau.cmi.chenxiaoqin.abstractFactory.Chicken;
import cn.edu.scau.cmi.chenxiaoqin.abstractFactory.Pork;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application{
	public void start(Stage primaryStage) {
		//上下布局
		BorderPane pane =new BorderPane();
		//信息展示文本区域
		TextArea inforArea=new TextArea(" ");
		inforArea.setEditable(false);
		inforArea.setWrapText(true);
		pane.setTop(inforArea);
		//操作区域
		Label tip1=new Label("我要");
		ComboBox<String> brandComboBox = new ComboBox<String>();
		brandComboBox.setValue("什么品牌");
		brandComboBox.getItems().addAll( "温氏","天邦","傲农" );  
		Label tip2=new Label("的");
		ComboBox<String> meatComboBox = new ComboBox<String>();
		meatComboBox.setValue("什么肉");
		meatComboBox.getItems().addAll( "牛肉","猪肉","鸡肉" );  
		Button okButton=new Button("确认");
		
		okButton.setOnAction(e->{
			String nameofbrand = brandComboBox.getValue();
			String kindofmeat = meatComboBox.getValue();
			if(nameofbrand.equals("什么品牌")||kindofmeat.equals("什么肉")) {
				inforArea.setText("请选择品牌和肉类！");
			}
			else {
				Brand brand=Brand.getBrand(nameofbrand);
				if(kindofmeat.equals("牛肉")) {
					Beef beef=brand.getBeef();
					inforArea.setText(beef.getBeefInfo());
				}
				else if(kindofmeat.equals("猪肉")) {
					Pork pork=brand.getPork();
					inforArea.setText(pork.getPorkInfo());
				}
				else {
					Chicken chicken=brand.getChicken();
					inforArea.setText(chicken.getChickenInfo());
				}
			}
		});
		
		HBox hBox=new HBox(15);
		hBox.setPadding(new Insets(15,15,15,15));
		hBox.getChildren().add(tip1);
		hBox.getChildren().add(brandComboBox);
		hBox.getChildren().add(tip2);
		hBox.getChildren().add(meatComboBox);
		hBox.getChildren().add(okButton);
		pane.setCenter(hBox);
		
		Scene scene =new Scene(pane,700,280);
		primaryStage.setTitle("抽象工厂模式");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}
}
